package com.hghivln.blog.controller;


import com.hghivln.blog.common.lang.Result;
import com.hghivln.blog.service.BlogGoodsService;
import io.swagger.annotations.Authorization;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 用户_博客点赞表 前端控制器
 * </p>
 *
 * @author hghivln
 * @since 2021-09-25
 */
@RestController
@RequestMapping("/blog-goods")
public class BlogGoodsController {

    @Autowired
    private BlogGoodsService blogGoodsService;

    /**
     * 点赞
     */
    @PostMapping("/goods/{blogId}")
    public Result<?> goods(@PathVariable Long blogId) {
        blogGoodsService.goods(blogId);
        return new Result<>("点赞成功");
    }

    /**
     * 查询博客是否点赞
     */
    @GetMapping("/getGoods/{blogId}")
    public Result<?> getGoods(@PathVariable Long blogId) {
        Integer count = blogGoodsService.getGoods(blogId);
        return new Result<>(count);
    }

    /**
     * 取消点赞
     */
    @PostMapping("/cancelGoods/{blogId}")
    public Result<?> cancelGoods(@PathVariable Long blogId) {
        blogGoodsService.removeByBlogId(blogId);
        return new Result<>("取消点赞成功");
    }
}
